package com.future.baselib.entity;

import android.text.TextUtils;

import com.future.baselib.utils.FLog;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 基础解析类
 * Created by jniu on 2017/5/17.
 */

public abstract class BaseResponse {


//    public int success;
    public String msg;
    public String data;
    public int code;

//    public int error;
//    public String info;

    public void parseJson(String json) {
//        FLog.e("responseJson --- " + json);
        try {
            if (TextUtils.isEmpty(json)) {
                return;
            }
            JSONObject object = new JSONObject(json);
//            error = object.optInt("error");
            msg = object.optString("msg");
            data = object.optString("data");
            code = object.optInt("code");
            if (code == 1) {
                parseInfo(data);
            }
//            info = object.optString("info");
//            if (error == 0) {
////                String info;
//                if (object.optJSONObject("info") != null) {
////                    info = object.optJSONObject("info").toString();
//                    parseInfo(info);
//                } else if (object.optJSONArray("info") != null) {
////                    info = object.optJSONArray("info").toString();
//                    parseInfo(info);
//                }
//            }
        } catch (JSONException e) {
            FLog.e("解析异常:" + e.getMessage() + "---json:" + json);
        }
    }

    public abstract void parseInfo(String content) throws JSONException;
}
